package com.minglead.crawler.enums;

import cn.hutool.core.util.ObjectUtil;
import com.minglead.crawler.entity.SelectEntity;
import com.minglead.crawler.util.StringUtils;

import java.util.ArrayList;
import java.util.List;

/**
 * @author bxh
 * @Description 舆情爬虫是否采用全局关键词
 * @date 2024/8/1
 */
public enum CrawlerGlobalKeyYesOrNoEnum {
    //0:否，1:是
    STOPPED("0", "否"),
    RUNNING("1", "是");


    /** 枚举值 */
    private final String code;

    /** 枚举描述 */
    private final String description;


    CrawlerGlobalKeyYesOrNoEnum(String code, String message) {
        this.code = code;
        this.description = message;
    }

    public String getCode() {
        return code;
    }

    public String getMessage() {
        return description;
    }

    /**
     * 获取下拉列表填充数据
     * @return 下拉列表填充数据
     */
    public static List<SelectEntity> getSelectList() {
        List<SelectEntity> result = new ArrayList<>();
        for (CrawlerGlobalKeyYesOrNoEnum row :
                CrawlerGlobalKeyYesOrNoEnum.values()) {
            SelectEntity data = new SelectEntity();
            data.setLabel(row.description);
            data.setVal(row.code);
            result.add(data);
        }
        return result;
    }

    public static CrawlerGlobalKeyYesOrNoEnum getEnum(String code) {
        if (ObjectUtil.isNotNull(code)) {
            CrawlerGlobalKeyYesOrNoEnum[] VALUES = CrawlerGlobalKeyYesOrNoEnum.values();
            for (CrawlerGlobalKeyYesOrNoEnum ele : VALUES) {
                if (StringUtils.equals(ele.code,code)) {
                    return ele;
                }
            }
        }
        return null;
    }
}
